import { createRouter, createWebHashHistory } from 'vue-router'
import routes from './routes'
import { useStoreOne } from '@/stores/storeOne'

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        ...routes,
        {
            path: '/:catchAll(.*)*',
            name: '404',
            redirect: '/error',
        },
    ],
})

router.beforeEach((to) => {
    console.log('即将跳转的路由', to)
    const storeOne = useStoreOne()
    storeOne.SET_CURRENT_ROUTE(to)
    if (to.meta.title) {
        document.title = to.meta.title as string
    }
})

export default router